package com.xhh.nphm.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhh.nphm.common.utils.DateUtils;
import com.xhh.nphm.system.domain.BUserTelNo;
import com.xhh.nphm.system.service.BUserTelNoService;
import com.xhh.nphm.system.mapper.BUserTelNoDao;
import org.springframework.stereotype.Service;

/**
 * 用户分机号服务实现类
* @author zz
* @description 针对表【bUserTelNo】的数据库操作Service实现
* @createDate 2022-09-22 13:21:38
*/
@Service
public class BUserTelNoServiceImpl extends ServiceImpl<BUserTelNoDao, BUserTelNo>
    implements BUserTelNoService{

    /**
     * 根据分机号查找分机号实体
     *
     * @param tno 分机号
     * @return 实体
     */
    @Override
    public BUserTelNo findOneByTelNo(String tno) {
        QueryWrapper<BUserTelNo> wrapper = new QueryWrapper<>();
        wrapper.eq("isDel",0);
        wrapper.eq("telNo",tno);
        return getBaseMapper().selectOne(wrapper);
    }


    /**
     * 更新分机号占用情况
     * @param bUserTelNo 分机号实体
     * @param loginName 登录名称（可空）
     * @param act 更新内容标识
     * @return 影响行数
     */
    @Override
    public int updateTelState(BUserTelNo bUserTelNo,String loginName,int act) {
        UpdateWrapper<BUserTelNo> wrapper = new UpdateWrapper<>();
        if (act == 0) {
            wrapper.set("useState",1);
            wrapper.set("loginName",loginName);
            wrapper.set("updateTime", DateUtils.getNowDate());
        }else if(act == 1){
            wrapper.set("useState",0);
        }
        wrapper.eq("id",bUserTelNo.getId());
        return getBaseMapper().update(null,wrapper);
    }
}




